#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re


print('匹配至少一个数字' + ' -----------------------------------------------------------------------------------------------------------------------')
# 所有的全部匹配，返回列表
pattern = re.compile(r'\d+')
m = pattern.findall('hello 123 456')
print(m)  # ['123', '456']


print('匹配0个或者1个数字' + ' -----------------------------------------------------------------------------------------------------------------------')
pattern = re.compile(r'\d?')
m = pattern.findall('hello 123 456')
print(m)  # ['', '', '', '', '', '', '1', '2', '3', '', '4', '5', '6', '']


print('匹配0个或无限个数字' + ' -----------------------------------------------------------------------------------------------------------------------')
pattern = re.compile(r'\d*')
m = pattern.findall('hello 123 456')
print(m)  # ['', '', '', '', '', '', '123', '', '456', '']


print('三个参数' + ' -----------------------------------------------------------------------------------------------------------------------')
pattern = re.compile(r'\d+')
m = pattern.findall('aaa123bbb456', 1, 10)
print(m)  # ['123', '4']


print('finditer' + ' -----------------------------------------------------------------------------------------------------------------------')
pattern = re.compile(r'\d+')
m = pattern.finditer('aaa123bbb456')
print(m)  # <callable-iterator object at 0x108168950>
for i in m:
    print(i.group())
# 123
# 456


